package level4project.v4modify_decorator.ctrl;

import level4project.v4modify_decorator.model.Light;
import level4project.v4modify_decorator.model.LightOffCommand;
import level4project.v4modify_decorator.model.LightOnCommand;
import level4project.v4modify_decorator.model.RemoteControl;
import level4project.v4modify_decorator.view.DecoratorBaseLightView;
import level4project.v4modify_decorator.view.DecoratorCapLightView;
import level4project.v4modify_decorator.view.LightView;

public class Controller {
	private Light[] lights = new Light[7];
	private LightView[] lightViews = new LightView[7];
	private RemoteControl rc;
	public Controller() {
		rc = new RemoteControl();
		for(int i=0;i<7;i++) {
			lights[i] = new Light(); // create model object
			lightViews[i] = new LightView();//create view object			
			lights[i].registerObserver(lightViews[i]);//register
			
			rc.setCommand(i, new LightOnCommand(lights[i]),
					               new LightOffCommand(lights[i]));			
		}	
		for(int i=0;i<7;i++) {
			lightViews[i] = new DecoratorCapLightView(new DecoratorBaseLightView(lightViews[i]));
		}
	//	lightViews[3] = new DecoratorCapLightView(lightViews[3]);
	//	lightViews[3] = new DecoratorCapLightView(lightViews[3]);
	}
	public Light[] getLights() {
		return lights;
	}
	public LightView[] getLightViews() {
		return lightViews;
	}
	public RemoteControl getRc() {
		return rc;
	}
	public void turnOnAll () {// update 1 facade method
		for(int i=0;i<7;i++) {
			rc.onButtonWasPushed(i);;
		}
	}
	
	public void turnOffAll() {// update 2 facade method
		for(int i=0;i<7;i++) {
			rc.offButtonWasPushed(i);;
		}
	}
	
}